package com.hospital.phyexam.controller;

import com.alibaba.fastjson.JSONObject;
import com.hospital.phyexam.service.AdminOfficeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/office")
public class AdminOfficeServiceController {
    @Autowired
    AdminOfficeService adminOfficeService;

    @RequestMapping(value = "/all", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    @ResponseBody
    public String getAll(){
        return adminOfficeService.getAllAdminOffice();
    }
    @RequestMapping(value = "/all1", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    @ResponseBody
    public String getAllAdmin(){
        return adminOfficeService.getAllAdmin();
    }
    @RequestMapping(value = "/add", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String add(@RequestBody String data){
        String num=JSONObject.parseObject(data).getString("ofcNum");
        String name=JSONObject.parseObject(data).getString("ofcName");
        String remark=JSONObject.parseObject(data).getString("ofcRemark");
        return adminOfficeService.insert(num,name,remark);
    }
    @RequestMapping(value = "/update", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String update(@RequestBody String data){
        int id=JSONObject.parseObject(data).getInteger("id");
        String num=JSONObject.parseObject(data).getString("ofcNum");
        String name=JSONObject.parseObject(data).getString("ofcName");
        String remark=JSONObject.parseObject(data).getString("ofcRemark");
        return adminOfficeService.update(id,num,name,remark);
    }
    @RequestMapping(value = "/delete", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String delete(@RequestBody String data){
        int id=JSONObject.parseObject(data).getInteger("id");
        return adminOfficeService.delete(id);
    }
}
